package LeetCode;

import java.util.Scanner;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/4/23.
// 
public class 盛最多水的容器 {
//    https://leetcode.cn/problems/container-with-most-water/description/
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] nums = new int[N];
        for (int i = 0; i < N; i++) {
            nums[i] = scan.nextInt();
        }
        System.out.println(maxArea(nums));
    }
    public static int maxArea(int[] height) {
        int max = 0,left = 0,right = height.length-1;
        while(left < right){
            int area = Math.min(height[left] ,height[right]) * (right - left);
            max = Math.max(area,max);
            if(height[left] < height[right]){
                left++;
            }else {
                right--;
            }
        }

        return max;
    }
}
